// pages/account/index.js
Page({
  data: {
    accountInfo: {
      balance: 128.50,
      points: 1280,
      level: 15,
      experience: 75
    },
    transactions: [
      {
        id: 1,
        type: "income",
        title: "签到奖励",
        amount: 25,
        time: "2024-01-15 09:00",
        status: "completed"
      },
      {
        id: 2,
        type: "expense",
        title: "购买徽章",
        amount: -29.9,
        time: "2024-01-14 16:30",
        status: "completed"
      },
      {
        id: 3,
        type: "income",
        title: "任务奖励",
        amount: 50,
        time: "2024-01-14 14:20",
        status: "completed"
      },
      {
        id: 4,
        type: "expense",
        title: "购买头像框",
        amount: -19.9,
        time: "2024-01-13 20:15",
        status: "completed"
      }
    ],
    quickActions: [
      { name: "充值", icon: "💰", action: "recharge" },
      { name: "提现", icon: "💳", action: "withdraw" },
      { name: "转账", icon: "🔄", action: "transfer" },
      { name: "账单", icon: "📊", action: "bills" }
    ]
  },

  onLoad: function (options) {
    wx.setNavigationBarTitle({
      title: '我的账户'
    })
  },

  onQuickActionTap: function(e) {
    const action = e.currentTarget.dataset.action
    
    switch(action) {
      case "recharge":
        this.onRechargeTap()
        break
      case "withdraw":
        this.onWithdrawTap()
        break
      case "transfer":
        this.onTransferTap()
        break
      case "bills":
        this.onBillsTap()
        break
    }
  },

  onRechargeTap: function() {
    wx.showModal({
      title: '账户充值',
      content: '选择充值金额：\n\n¥10 - 获得100积分\n¥50 - 获得550积分\n¥100 - 获得1200积分',
      showCancel: true,
      cancelText: '取消',
      confirmText: '充值',
      success: function(res) {
        if (res.confirm) {
          wx.showToast({
            title: '充值功能开发中',
            icon: 'none'
          })
        }
      }
    })
  },

  onWithdrawTap: function() {
    wx.showModal({
      title: '账户提现',
      content: '当前余额：¥128.50\n\n提现功能正在开发中，敬请期待！',
      showCancel: true,
      cancelText: '关闭',
      confirmText: '确定'
    })
  },

  onTransferTap: function() {
    wx.showToast({
      title: '转账功能开发中',
      icon: 'none'
    })
  },

  onBillsTap: function() {
    wx.showToast({
      title: '账单详情功能开发中',
      icon: 'none'
    })
  },

  onTransactionTap: function(e) {
    const transaction = e.currentTarget.dataset.transaction
    
    wx.showModal({
      title: '交易详情',
      content: `类型：${transaction.type === 'income' ? '收入' : '支出'}\n金额：${transaction.amount > 0 ? '+' : ''}${transaction.amount}\n时间：${transaction.time}\n状态：${transaction.status === 'completed' ? '已完成' : '处理中'}`,
      showCancel: true,
      cancelText: '关闭',
      confirmText: '确定'
    })
  }
})
